package sum.MarriagesAndDivorces;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import sum.DatasetBean.MarriageDatasetBean;

import java.io.IOException;


public class SumMarriagesReducer extends Reducer<Text, MarriageDatasetBean,Text,MarriageDatasetBean> {
    MarriageDatasetBean outValue = new  MarriageDatasetBean();

    @Override
    protected void reduce(Text key, Iterable<MarriageDatasetBean> values,Context context) throws IOException, InterruptedException {
        float totalMarriages = 0;
        float totalDivorces = 0;

        for (MarriageDatasetBean value : values){
            totalMarriages += value.getMarriages();
            totalDivorces += value.getDivorces();
        }

        outValue.set(totalMarriages,totalDivorces);
        context.write(key,outValue);
    }
}
